<?php

require_once APPPATH . 'dao/configurationManager.php';

class ViewLayer extends CI_Controller {

    public function index() {
        if ($this->session->userdata('logged_in')) {
            if (!$this->input->post('submit')) {
                $data = array();
                $data['layer'] = array('name' => 'layer',
                    'id' => 'layer',
                    'value' => $this->input->post('layer'), // set_value('bboxMinX'),
                    'maxlength' => 100,
                    'size' => 100
                );
                $data['srs'] = array('name' => 'srs',
                    'id' => 'srs',
                    'value' => $this->input->post('srs'), // set_value('bboxMinX'),
                    'maxlength' => 50,
                    'size' => 50
                );
                $data['format'] = array('name' => 'format',
                    'id' => 'format',
                    'value' => $this->input->post('format'), // set_value('bboxMinX'),
                    'maxlength' => 50,
                    'size' => 50
                );
                $data['bbox'] = array('name' => 'bbox',
                    'id' => 'bbox',
                    'value' => $this->input->post('bbox'), // set_value('bboxMinX'),
                    'maxlength' => 100,
                    'size' => 100
                );
                $data['minZoomLevel'] = array('name' => 'minZoomLevel',
                    'id' => 'minZoomLevel',
                    'value' => $this->input->post('minZoomLevel'), // set_value('bboxMinX'),
                    'maxlength' => 3,
                    'size' => 5,
                    'type' => 'hidden'
                );
                $data['maxZoomLevel'] = array('name' => 'maxZoomLevel',
                    'id' => 'maxZoomLevel',
                    'value' => $this->input->post('maxZoomLevel'), // set_value('bboxMinX'),
                    'maxlength' => 3,
                    'size' => 5,
                    'type' => 'hidden'
                );
                $data['resolutions'] = $this->input->post('resolutions');
                add_css(array('/assets/css/viewLayer.css'));
                add_js(array('assets/libs/Openlayers/OpenLayers.js',
                    'assets/libs/Openlayers/proj4js-compressed.js',
                    'assets/libs/Openlayers/defs/EPSG22185.js',
                    'assets/js/util.js','assets/js/singleVisualizator.js'));
                $this->load->view('pages/header.php');
                $this->load->view('pages/viewLayer.php', $data);
                $this->load->view('pages/footer.php');
            }
        } else {
            redirect('login');
        }
    }

    public function getSRSResolutions($srs) {
        $srs = urldecode($srs);
        $srsData = ConfigurationManager::getInstance()->getGridData($srs);
        if ($srsData) {
            echo json_encode($srsData);
        } else {
            echo json_encode(null);
        }
    }

}